<?php

function loadfile() {
    if (count($GLOBALS['config']['paths']) === 1) {
        $GLOBALS['config']['paths'][] = 'index';
    }
    $sPath = DS . implode(DS, $GLOBALS['config']['paths']) . '.php';
    if (is_file(__WWWROOT__ . $sPath)) {
        loadfile_include(__WWWROOT__ . $sPath);
    } else if (is_file($GLOBALS['pagedir'] . $sPath)) {
        loadfile_include($GLOBALS['pagedir'] . $sPath);
    } else {
        echo '文件丢失：' . $sPath;
    }
}

function loadfile_include($path) {
    if (!isset($GLOBALS['script'])) $GLOBALS['script'] = array();
?>
<script>
const vue = VueInit(<?=json_encode($GLOBALS['config'])?>);
vue.el = '#vue_content';
vue.created = function () {
    if (vue.data.config.pagemode === 'iframe' && self === top && vue.data.config.paths[0] === 'panel') {
        location.href = '/panel' + vue.data.config.PageFileExt + '#/panel/index' + vue.data.config.PageFileExt;
    }
};
</script>
<span id="vue_content"><?php include($path);?></span>
<?php
foreach ($GLOBALS['script'] as $script) {
    call_user_func($script);
}
?>
<script>
new Vue(vue);
</script>
<?php
}

